//
//  OMCInteraction.m
//  InteractiveNotification
//
//  Created by GuochengLiu on 2017/1/17.
//  Copyright © 2017年 sumavision. All rights reserved.
//

#import "OMCInteraction.h"
#import <AFNetworking.h>

@implementation OMCInteraction

+ (instancetype)sharedInstance
{
    static dispatch_once_t once;
    static id sharedInstance;
    dispatch_once(&once, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

- (instancetype)init
{
    if (self = [super init]) {
        self.currentInteractant = [[NSUserDefaults standardUserDefaults] valueForKey:@"currentInteractant"];
    }
    return self;
}

- (void)pushWithMedia:(NSString *)media
{
    [self pushWithMedia:media receiver:nil];
}

- (void)pushWithMedia:(NSString *)media receiver:(NSString *)receiver
{
    if (receiver == nil) {
        receiver = self.currentInteractant;
    }
    
    // Fake code, simulate a http request, similar to a media push action
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://www.baidu.com"]];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:@"25894431" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        NSLog(@"downloadProgress %@", downloadProgress);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"success %@", responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"failure %@", error.localizedDescription);
    }];
}

@end
